//
//  Api+Path.swift
//  App
//
//  Created by yuany on 2019/4/10.
//

import Foundation
import RoutingKit

protocol RawStringPathComponent {
    var rawValue: String { get }
    var asPath: PathComponent { get }
}

extension RawStringPathComponent {
    var asPath: PathComponent { .init(stringLiteral: rawValue) }
}

extension RoutesBuilder {
    func grouped(_ path: RawStringPathComponent) -> RoutesBuilder {
        return grouped(path.asPath)
    }
}

// MARK: - Path
extension Api {
    enum V1: String, RawStringPathComponent {
        case group = "api"
        
        var relativeValue: String {
            switch self {
            case .group:
                return rawValue
            }
        }
        
        var relativePath: String { "/" + relativeValue }
    }
}

// MARK: - Users
extension Api.V1 {
    enum Users: String {
        case group = "users"
        case login
        case register
        case info
        case newPassword
        case changePasswordCode
        case activateCode
        case oauthToken = "oauth/token"
        
        var relativeValue: String {
            switch self {
            case .group:
                return Api.V1.group.relativeValue + "/" + rawValue
            default:
                return type(of: self).group.relativeValue + "/" + rawValue
            }
        }
    }
}

// MARK: - Token
extension Api.V1 {
    enum Token: String {
        case group = "token"
        case refresh
        case revoke
        
        var relativeValue: String {
            switch self {
            case .group:
                return Api.V1.group.relativeValue + "/" + rawValue
            default:
                return type(of: self).group.relativeValue + "/" + rawValue
            }
        }
    }
}

// MARK: - Account
extension Api.V1 {
    enum Account: String {
        case group = "account"
        case info
        case update
        
        var relativeValue: String {
            switch self {
            case .group:
                return Api.V1.group.relativeValue + "/" + rawValue
            default:
                return type(of: self).group.relativeValue + "/" + rawValue
            }
        }
    }
}

// MARK: - Protected
extension Api.V1 {
    enum Protected: String {
        case group = "protected"
        case basic
        case token
        
        var relativeValue: String {
            switch self {
            case .group:
                return Api.V1.group.relativeValue + "/" + rawValue
            default:
                return type(of: self).group.relativeValue + "/" + rawValue
            }
        }
    }
}

// MARK: - Blog
extension Api.V1 {
    enum Blog: String, RawStringPathComponent {
        case group = "blog"
        case list
        case detail
        
        var relativeValue: String {
            switch self {
            case .group:
                return Api.V1.group.relativeValue + "/" + rawValue
            default:
                return type(of: self).group.relativeValue + "/" + rawValue
            }
        }
    }
}

// MARK: - Token
extension Api.V1 {
    
}
